package com.mobi.cacti.rabbit.response;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;

import org.holoeverywhere.app.AlertDialog;

import android.content.Context;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.util.Log;

import com.mobi.cacti.model.ReqCactiData;
import com.mobi.cacti.model.ReqTFASTicket;

public class Cache
{
	private  static String requestSessionID;
	public static UserInfo userInfo;
    public static ReqMobileLogin reqMobileLogin;
	public static ReqCustomerServiceInfo reqW4CusInfo;
	public static ReqTicketCount[] ticketCountArray;
	
    public static int menuClick = 0;
	public static ReqCactiData reqCactiData;
	public static ReqTFASTicket reqTFASTicket;
	
	public static Bundle graphDetailStateBundle;
	public static Bundle ticketListStateBundle;
	
	public static int getTotlaTicketCount()
	{
		int countTicket = 0;
		for(int i = 0 ; i < ticketCountArray.length ; i++)
		{
			if(ticketCountArray[i] != null)
			{
				countTicket += ticketCountArray[i].ticketCount;
			}
		}
		
		return countTicket;
	}
	
	public static String getRequestSessionID()
	{
		//Format COMiQ201307290910310001
		if(requestSessionID == null || requestSessionID.equals(""))
		{
			DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
			Date date = new Date();
			String dateTime = dateFormat.format(date);
			
			long timeStamp = TimeUnit.MILLISECONDS.toSeconds(((System.currentTimeMillis())));

			requestSessionID = "COMiQ"+dateTime+timeStamp;
		}
		
		Log.i("tai","RequestID = " + requestSessionID);
		return requestSessionID;
	}
	
	public static void showNoInternetAlertDialog(Context context) {
		AlertDialog.Builder builder = new AlertDialog.Builder(context);
		builder.setTitle("Failed")
				.setMessage("No internet access")
				.setPositiveButton("Retry", null);
				//.setNegativeButton("Cancel", null);
		AlertDialog alertDialog = builder.create();
		alertDialog.show();
	}
	
	public static boolean isNetworkAvailable(Context context) 
	{
		boolean isNetworkConnectionExist = ((ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo() != null;
		
		Log.i("tai", "Internet connection = " + isNetworkConnectionExist);
		
	    return isNetworkConnectionExist;
	}
}

